const Base = require("../base.js");
var txyoss = require("./txyoss");
/*腾讯云oss上传*/
let ws = null;
module.exports = class extends Base {
  async indexAction() {
    const file = this.file("file");
    let { imgurl, fileName, Key } = await txyoss.upimgFile(
      file,
      this.post("typeName"),
      function (data) {
        console.log(data);
        try {
          ws.emit("jindu", data);
        } catch (e) {}
      }
    );
    if (imgurl.indexOf("mp4") > 0) {
      const getImg = await txyoss.videojt(Key);
      await txyoss.upbuff(
        getImg,
        "",
        "",
        "videojt/" + this.post("typeName") + "/" + fileName + ".jpg"
      );
    }
    try {
      ws.broadcast(this.post("typeName"), {
        imgurl: imgurl,
        fileName,
      });
    } catch (e) {
      console.log(e);
    }
    this.json({
        location:imgurl
    })
  }
  // 客户端发送上传的ws消息 获取this
  parameterUploadProgressAction() {
    console.log("6666");
    ws = this;
  }
};
